package com.li.utils;

import com.li.common.ModelName;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.Objects;
@Component
public class IdHandle {
    @Resource
    private IdUtils idUtils;

    /**
     * 如果id为null，则抛出异常
     * idUtils.keyParser(uid)  => 如果uid不存在，则创建一个 ,如果uid存在，则返回uid
     * @param id
     * @param modelName
     * @return
     */
    public String uidParse(Integer id,String modelName){
        String uid = idUtils.getUid(id,modelName);
        if (Objects.equals(uid, "-1")){
            throw new RuntimeException("参数非法!id不能为null");
        }
        String s = idUtils.keyParser(uid);
        if (Objects.equals(s, "nonId")){
            uid = idUtils.createUid(id, modelName);
        }
        return uid;
    }
}
